<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css" />
<script src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js" type="text/javascript"></script>
<%--分页显示的开始 --%>
<div id="pagediv" align="center" style="width: 80%; margin: 0 auto; margin-top: 50px;">
	<ul class="pagination" style="text-align: center; margin-top: 10px;">
		<li><a>共${page.totalPageNum}页/第${page.currentPageNum}页</a></li>
		<li >
			<a id="fistPage" href="${pageContext.request.contextPath}/${page.url}&num=1" aria-label="Previous"> <span aria-hidden="true">首页</span>
			</a></li>
		<li >
			<a id="prePage" href="${pageContext.request.contextPath}/${page.url}&num=${page.prePageNum}" aria-label="Previous"> <span aria-hidden="true">上一页</span>
			</a></li>

		<c:forEach begin="${page.startPage}" end="${page.endPage}"
				   var="pagenum">
			<li><a id="${pagenum}" href="${pageContext.request.contextPath}/${page.url}&num=${pagenum}">${pagenum}</a></li>
		</c:forEach>
		<li ><a id="nextPage"
				href="${pageContext.request.contextPath}/${page.url}&num=${page.nextPageNum}"
				aria-label="Next"> <span aria-hidden="true">下一页</span>
		</a></li>
		<li ><a id="LastPage"
				href="${pageContext.request.contextPath}/${page.url}&num=${page.totalPageNum}"
				aria-label="Next"> <span aria-hidden="true">末页</span>
		</a></li>
		<li style="align: center"><a>
			<input type="text" id="pagenum" style="width:20px;height:18px;"
				   name="pagenum" size="1" /></a><a href="javascript:void(0)"
													onclick="jump()">前往</a></li>
	</ul>

	<script type="text/javascript">
		function jump(){
			var totalpage = ${page.totalPageNum};
			var pagenum = document.getElementById("pagenum").value;
			//判断输入的是一个数字
			var reg =/^[1-9][0-9]{0,1}$/;
			if(!reg.test(pagenum)){
				//不是一个有效数字
				alert("请输入符合规定的数字");
				return ;
			}
			//判断输入的数字不能大于总页数
			if(parseInt(pagenum)>parseInt(totalpage)){
				//超过了总页数
				alert("不能大于总页数");
				return;
			}
			//转向分页显示的Servlet
			window.location.href="${pageContext.request.contextPath}/${page.url}&num="+pagenum;
		}
		$(function(){
			//页面加载完毕之后获取到上一页和下一页对应的a标签
			$("#${page.currentPageNum}").css("background-color","#9acfea");
			$("#${page.currentPageNum}").attr("href","javascript:void(0);");
			if("${page.currentPageNum}" == "1"){
				$("#prePage").hide();
				$("#fistPage").hide();
			}
			//如果目前在最后一页,隐藏下一页
			if("${page.currentPageNum}" == "${page.totalPageNum}"){
				$("#nextPage").hide();
				$("#LastPage").hide();
			}
			if("${page.totalPageNum}" == "0"){
				$("#pagediv").hide();
			}


		});
	</script>
</div>
<%--分页显示的结束--%>
